package com.clayecloud.common.admin.services.Impl;

import com.clayecloud.common.admin.services.UserService;
import com.clayecloud.common.entity.House;
import com.clayecloud.common.entity.User;
import com.clayecloud.common.mappers.UserMapper;
import com.clayecloud.common.utils.MessageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("AdminUserServiceImpl")
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public MessageUtil insertSelective(User record) {
        return userMapper.insertSelective(record) > 0 ? MessageUtil.success("添加成功") : MessageUtil.fail("添加失败，请联系系统管理员");
    }

    @Override
    public MessageUtil deleteByPrimaryKey(Integer userId) {
        return userMapper.deleteByPrimaryKey(userId) > 0 ? MessageUtil.success("删除成功") : MessageUtil.fail("删除失败，请联系系统管理员");
    }

    @Override
    public MessageUtil updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record) > 0 ? MessageUtil.success("修改成功") : MessageUtil.fail("修改失败，请联系系统管理员");
    }

    @Override
    public MessageUtil<List<User>> selectAll(Integer size, Integer page) {
        PageHelper.startPage(page,size);
        List<User> users = userMapper.selectAll();
        PageInfo pageInfo = new PageInfo(users);
        Map result = new HashMap();
        result.put("list",users);
        result.put("total",pageInfo.getTotal());
        return MessageUtil.success("查询成功").add(result);
    }
}
